import { Effect, ImmerReducer, Reducer, Subscription, } from 'umi';
import { reqAllHuiYuan } from '../api/huiyuanReq'

interface ModelState {
    huiyuanList: object;
}

interface ModelsType {
    state: ModelState;
    effects: {
        getHuiyuan: Effect;
    };
    reducers: {
        initHuiyuan: ImmerReducer
    },
    subscriptions:{
        setup(obj:any):void
    }

}

const BannerModel: ModelsType = {

    state: {
        huiyuanList: [],
    },
    subscriptions:{
        setup({ history, dispatch }){
            dispatch({
                type:"getHuiyuan",
            }); 
        }
    },
    effects: {
        *getHuiyuan({ payload }, { call, put }) {
            const res = yield call(reqAllHuiYuan)
            // console.log(res);//这是获取到的结果
            yield put({
                type: 'initHuiyuan',
                payload: res.data
            })
        },
    },
    reducers: {
        initHuiyuan(state, action) {
            // console.log(state, action);
            state.huiyuanList = action.payload
        },
    },

};

export default BannerModel;
